﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace List_of_All_databases
{
    class clsReturnDBList
    {
        public System.Data.DataTable dtDBList(string strServer, string strLogin, string strPassword)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
            System.Data.DataSet ds = new System.Data.DataSet();

            string strConString = "Data Source=" + strServer + ";Persist Security Info=True;User ID="+strLogin+";Password="+strPassword;
            //Data Source=(LOCAL);Initial Catalog=test;Persist Security Info=True;User ID=test;Password=test
            cn.ConnectionString = strConString;
            cn.Open();

            cmd.CommandText = "select [name] from dbo.sysdatabases order by name";
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection = cn;
            
            da.SelectCommand = cmd;

            da.Fill(dt);

            cn.Close();

            return dt;
        }
    }
}
